from time import sleep

from django.contrib import admin
from goods import models
from celery_tasks.static_html.tasks import generate_static_list_search_html,generate_static_sku_detail_html


# Register your models here.


class GoodsAdmin(admin.ModelAdmin):
    list_display = ('name','sales','comments')

    def delete_model(self, request, obj):
        obj.delete()
        generate_static_list_search_html.delay()

class SKUAdmin(admin.ModelAdmin):
    list_display = ('name', 'price')

    def save_model(self, request, obj, form, change):
        obj.save()

        generate_static_list_search_html.delay()

    def delete_model(self, request, obj):
        obj.delete()
        generate_static_list_search_html.delay()

class SKUImageAdmin(admin.ModelAdmin):


    def save_model(self, request, obj, form, change):
        print(obj.image)
        print(obj.image.url)
        print(type(obj.image))
        print(type(obj.image.url))

        generate_static_sku_detail_html.delay(obj.sku.id)


admin.site.register(models.Goods,GoodsAdmin)
admin.site.register(models.SKU,SKUAdmin)
admin.site.register(models.SKUImage,SKUImageAdmin)
